package com.cskaoyan.controller.category;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.CommonData;
import com.cskaoyan.bean.bo.category.CategoryBo;
import com.cskaoyan.bean.po.ohter.MarketCategory;
import com.cskaoyan.bean.vo.category.CategoryListVo;
import com.cskaoyan.service.category.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhang Tao
 * @version 1.0.0
 * @description
 * @date since 2022-07-20 14:01
 */
@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @GetMapping("list")
    public BaseRespVo categoryList() {
        CommonData categoryList = categoryService.selectAll();

        return BaseRespVo.ok(categoryList);

    }
    @GetMapping("l1")
    public BaseRespVo listcategoryL1(){
        CommonData lableList =  categoryService.selectLable();
        return BaseRespVo.ok(lableList);
    }
    @PostMapping("create")
    public BaseRespVo createCategory(@RequestBody MarketCategory category){
        MarketCategory category1 =  categoryService.createCategory(category);
        return BaseRespVo.ok(category1);
    }

    @PostMapping("update")
   public BaseRespVo updateCatogory(@RequestBody CategoryBo categoryBo){
        // if (categoryBo.getPid()==null) {
        //     categoryBo.setPid(0);
        // }
      categoryService.updateCategory(categoryBo);
      return BaseRespVo.ok();
    }
    @PostMapping("delete")
    public BaseRespVo deleteCategory(@RequestBody CategoryListVo categoryListVo){
        categoryService.deleteCategory(categoryListVo);
        return BaseRespVo.ok();
    }


   /*
    @RequestMapping("read")

   */

}
